package com.hhq.usercenter.security;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.hhq.usercenter.domain.pojo.MenuInfo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.SpringSecurityCoreVersion;

import java.util.List;

/**
 * <p>Description: 菜单权限 </p>
 *
 * @author : xiaodong.yang
 * @date : 2024/1/10 10:18
 */
@Setter
@Getter
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class MenuGrantedAuthority implements GrantedAuthority {

    private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
    private String role;

    private List<MenuInfo> menus;

    public MenuGrantedAuthority(String role, List<MenuInfo> menus) {
        this.role = role;
        this.menus = menus;
    }

    @Override
    public String getAuthority() {
        return role;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof MenuGrantedAuthority) {
            return role.equals(((MenuGrantedAuthority) obj).role);
        }

        return false;
    }

    @Override
    public int hashCode() {
        return this.role.hashCode();
    }

    @Override
    public String toString() {
        return this.role;
    }

    public List<MenuInfo> getMenus() {
        return menus;
    }
}
